﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VK.Comm;
using VK.Casemeet.Areas;

namespace VK.Casemeet.Web.Admin
{
    public partial class AreaAdd : System.Web.UI.Page
    {
        public int parentID = 0;

        protected void Page_Load(object sender, EventArgs e)
        {
            (this.Master as Site).SiteMapPathControl.MapPathList = new List<MapPath>(){
                new MapPath{ Text="桌面",Url="/Admin/Home.aspx"},
                new MapPath{ Text="地区",Url="/Admin/Merchants/AreaList.aspx"},
                new MapPath{ Text="新建地区",Url="#"}
            };

            parentID = Util.GetQueryInt("ParentID");

            if (!IsPostBack)
            {
                AreaHelper.BindAreaDDL(ddlParentID, OptionType.Search, null);
                ddlParentID.SelectedValue = parentID.ToString();
            }
        }

        protected void butSave_Click(object sender, EventArgs e)
        {
            AreaEntity area = LoadEntity();

            if (AreaBLL.InsertArea(area) > 0)
            {
                Message.Msg(this.Page, CS.MsgAddSuccess, MessageType.Success);
                Util.ClearControl((this.Master as Site).contentBody.Controls);
                ddlParentID.SelectedValue = parentID.ToString();
                txtHits.Text = "0";
            }
            else
            {
                Message.Msg(this.Page, CS.MsgAddFailure, MessageType.Failure);
            }
        }

        protected AreaEntity LoadEntity()
        {
            AreaEntity area = new AreaEntity();
            area.Name = txtName.Text.Trim();
            area.ParentID = int.Parse(ddlParentID.SelectedValue);
            return area;
        }
    }
}